package com.albermark.photoorganizer.filefilter;

import java.io.File;
import java.io.FileFilter;

import org.springframework.util.Assert;

/**
 * 
 * @author Nuno Ferreira
 *
 */
public class ExtensionFileFilter implements FileFilter {

	private final String[] extensions;

	/**
	 * 
	 * @param extensions
	 */
	public ExtensionFileFilter(String...extensions) {
		
		Assert.notEmpty(extensions);
		
		this.extensions = extensions;
	}
	
	/**
	 * {@inheritDoc}
	 */
	public boolean accept(File file) {
		
		if (file.isDirectory()) {

			return true;

		} else {
			
			for (String extension : extensions) {
				if (file.getName().toLowerCase().endsWith(extension.toLowerCase())) {
					return true;
				}
			}
		}
		return false;
	}
}
